<?php

use App\Helpers\CSRF;
use App\Helpers\HTML;
use App\Helpers\URL;

if ($event !== 'contactCreate') { ?>
<?php $app->render('templates/dashboard_open', ['app' => $app, 'title' => 'Agregar contacto']) ?>
  <main class="card is-full-width max-w-lg mx-auto">
    <header>
      <h1>Agregar contacto</h1>
    </header>
<?php } ?>
    <div id="contactCreate">
      <?php if (isset($error)) { ?>
        <?php $app->render('components/error', ['error' => $error]) ?>
      <?php } ?>
      <form action="<?= URL::event('contacts/create', null, 'contactCreate') ?>" method="post" enctype="multipart/form-data" target=htmz>
        <input type="hidden" name="<?= CSRF::getVarname() ?>" value="<?= $app->local(CSRF::getVarname()) ?>">
        <p>
          <label for="fullname">Nombre<span class="text-error">*</span></label>
          <input type="text" name="fullname" id="fullname" placeholder="Juan Pérez" value="<?= $values['fullname'] ?>" class="<?= $status['fullname'] ?>">
          <small class="text-error"><?= HTML::esc($validations['fullname']) ?></small>
        </p>
        <p>
          <label for="phone">Teléfono<span class="text-error">*</span></label>
          <input type="tel" name="phone" id="phone" placeholder="1-(555)-555-5555" value="<?= $values['phone'] ?>" class="<?= $status['phone'] ?>">
          <small class="text-error"><?= HTML::esc($validations['phone']) ?></small>
        </p>
        <p>
          <label for="email">Correo</label>
          <input type="email" name="email" id="email" placeholder="juan.perez@email.com" value="<?= $values['email'] ?>" class="<?= $status['email'] ?>">
          <small class="text-error"><?= HTML::esc($validations['email']) ?></small>
        </p>
        <p>
          <label for="company">Empresa</label>
          <input type="text" name="company" id="company" placeholder="Tech Solutions S.A. de C.V." value="<?= $values['company'] ?>" class="<?= $status['company'] ?>">
          <small class="text-error"><?= HTML::esc($validations['company']) ?></small>
        </p>
        <p>
          <label for="website">Sitio web</label>
          <input type="url" name="website" id="website" placeholder="https://www.techsolutions.com" value="<?= $values['website'] ?>" class="<?= $status['website'] ?>">
          <small class="text-error"><?= HTML::esc($validations['website']) ?></small>
        </p>
        <p>
          <label for="birthday">Cumpleaños</label>
          <input type="date" name="birthday" id="birthday" value="<?= $values['birthday'] ?>" class="<?= $status['birthday'] ?>">
          <small class="text-error"><?= HTML::esc($validations['birthday']) ?></small>
        </p>
        <p>
          <label for="photo">Foto</label>
          <input type="file" name="photo" id="photo" class="<?= $status['photo'] ?>">
          <small class="text-error"><?= HTML::esc($validations['photo']) ?></small>
        </p>
        <p>
          <label for="notes">Notas</label>
          <textarea name="notes" id="notes" cols="48" rows="4" placeholder="Ingresa notas adicionales sobre el contacto" class="<?= $status['notes'] ?>"><?= HTML::esc($values['notes']) ?></textarea>
          <small class="text-error"><?= HTML::esc($validations['notes']) ?></small>
        </p>
        <p class="text-right">
          <a href="<?= URL::site('contacts') ?>" class="button secondary">Cancelar</a>
          <input type="submit" value="Guardar" class="button primary">
        </p>
      </form>
    </div>
<?php if ($event !== 'contactCreate') { ?>
  </main>
<?php $app->render('templates/dashboard_close', ['app' => $app]) ?>
<?php } ?>
